package com.cn.wanxi.service.impl;
import com.cn.wanxi.data.ProductData;
import com.cn.wanxi.data.UserData;
import com.cn.wanxi.data.impl.ProductImpl;
import com.cn.wanxi.data.impl.UserImpl;
import com.cn.wanxi.model.ProductModel;
import com.cn.wanxi.service.IProductService;
import java.util.List;

public class ProductServiceImpl implements IProductService {
    @Override
    public List<ProductModel> findAll(ProductModel productModel) {
        ProductData productData = new ProductImpl();
        return productData.findAll(productModel);

    }

    @Override
    public ProductModel findById(Integer id) {
        ProductData productData = new ProductImpl();
        return productData.findById(id);
    }

    @Override
    public String edit(ProductModel productModel) {
        ProductData productData = new ProductImpl();
    //        ProductData model = productData.findByPorductNameForEdit(productModel);
            return productData.edit(productModel) == 1 ? "success" : "error";

    }

    @Override
    public String Adding(ProductModel productModel) {
        ProductData productData = new ProductImpl();
        ProductModel model = productData.findById(productModel.getProductId());
        if (model != null) {
            return "isHave";
        } else {
            int result = productData.Adding(productModel);
            return result == 1 ? "success" : "error";
        }

    }

    @Override
    public String del(Integer id) {
        ProductData productData = new ProductImpl();
        return productData.del(id) == 1 ? "success" : "error";
    }



}
